/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.Service
*        文件名:             PermissionService.svc.cs
*        创建系统时间:       2012/11/2 19:07:05
*        创建年份:           2012
*
/*****************************************************************************/

namespace ECP.Service
{
    using System;
    using System.Data;
    using System.Reflection;
    using System.ServiceModel;
    using ECP.DataAccess;
    using ECP.DataAccess.Utilities;
    using ECP.Interface;
    using ECP.Model;
    using ECP.Utilities;

    [ServiceBehavior(Namespace = "http://jiangguang.net.cn/")]
    public partial class PermissionService : MarshalByRefObject, IPermissionService
    {
        private static PermissionService instance = null;
        private static object locker = new object();

        public string AddPermission(BaseUserInfo userInfo, string permission)
        {
            string str = string.Empty;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BasePermissionAdminDao dao = new BasePermissionAdminDao(dbHelper, userInfo);
                string statusCode = string.Empty;
                BasePermissionEntity permissionEntity = new BasePermissionEntity
                {
                    Code = permission,
                    Enabled = true
                };
                str = dao.Add(permissionEntity, out statusCode);
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return str;
        }

        public string AddRole(BaseUserInfo userInfo, string role)
        {
            string str = string.Empty;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRoleDao dao = new BaseRoleDao(dbHelper, userInfo);
                string statusCode = string.Empty;
                BaseRoleEntity roleEntity = new BaseRoleEntity
                {
                    Realname = role,
                    Category = "Role",
                    Enabled = true
                };
                str = dao.Add(roleEntity, out statusCode);
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return str;
        }

        public string AddUserToRole(BaseUserInfo userInfo, string userName, string roleName)
        {
            string str = string.Empty;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string str2 = new BaseUserDao(dbHelper, userInfo).FindID(BaseUserTable.FieldUsername, userName);
                string str3 = new BaseRoleDao(dbHelper, userInfo).FindID(BaseRoleTable.FieldRealname, roleName);
                if (!string.IsNullOrEmpty(str2) && !string.IsNullOrEmpty(str3))
                {
                    str = new BaseUserRoleDao(dbHelper, userInfo).AddToRole(str2, str3);
                }
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return str;
        }

        public int DeletePermission(BaseUserInfo userInfo, string permissionCode)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BasePermissionAdminDao dao = new BasePermissionAdminDao(dbHelper, userInfo);
                string str = dao.FindID(BasePermissionTable.FieldCode, permissionCode);
                if (!string.IsNullOrEmpty(str))
                {
                    num = dao.Delete(str);
                }
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int DeleteRole(BaseUserInfo userInfo, string role)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRoleDao dao = new BaseRoleDao(dbHelper, userInfo);
                string str = dao.FindID(BaseRoleTable.FieldRealname, role);
                if (!string.IsNullOrEmpty(str))
                {
                    num = dao.Delete(str);
                }
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public DataTable GetLicensePermissionByUser(BaseUserInfo userInfo, string userID)
        {
            return this.GetPermissionDTByPermission(userInfo, userID, "LicensePermission");
        }

        public DataTable GetModuleDT(BaseUserInfo userInfo)
        {
            return this.GetModuleDTByUser(userInfo, userInfo.ID);
        }

        public DataTable GetModuleDTByPermission(BaseUserInfo userInfo, string userID, string permissionCode)
        {
            DataTable dTByPermission = new DataTable(BasePermissionTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                dTByPermission = new BaseModuleDao(dbHelper, userInfo).GetDTByPermission(userID, permissionCode);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dTByPermission;
        }

        public DataTable GetModuleDTByUser(BaseUserInfo userInfo, string userID)
        {
            DataTable dT = new DataTable(BaseModuleTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseModuleDao dao = new BaseModuleDao(dbHelper, userInfo);
                if (userInfo.IsAdministrator)
                {
                    dT = dao.GetDT();
                }
                else
                {
                    dT = dao.GetDTByUser(userID);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dT;
        }

        public DataTable GetOrganizeDTByPermission(BaseUserInfo userInfo, string userID, string permissionScopeCode)
        {
            DataTable organizeDT = new DataTable(BaseOrganizeTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                if (string.IsNullOrEmpty(permissionScopeCode))
                {
                    organizeDT = new BaseOrganizeDao(dbHelper, userInfo).GetDT();
                    organizeDT.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
                    return organizeDT;
                }
                organizeDT = new BaseResourcePermissionScopeDao(dbHelper, userInfo).GetOrganizeDT(userInfo.ID, permissionScopeCode);
                organizeDT.DefaultView.Sort = BaseOrganizeTable.FieldSortCode;
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return organizeDT;
        }

        public string[] GetOrganizeIDsByPermission(BaseUserInfo userInfo, string userID, string permissionScopeCode)
        {
            string[] organizeIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string.IsNullOrEmpty(permissionScopeCode);
                organizeIDs = new BaseResourcePermissionScopeDao(dbHelper, userInfo).GetOrganizeIDs(userID, permissionScopeCode);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return organizeIDs;
        }

        public DataTable GetPermissionDT(BaseUserInfo userInfo)
        {
            return this.GetPermissionDTByUser(userInfo, userInfo.ID);
        }

        public DataTable GetPermissionDTByPermission(BaseUserInfo userInfo, string userID, string permissionCode)
        {
            DataTable dTByUser = new DataTable(BasePermissionTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BasePermissionAdminDao dao = new BasePermissionAdminDao(dbHelper, userInfo);
                string iD = dao.FindID(BasePermissionTable.FieldCode, permissionCode);
                if (string.IsNullOrEmpty(iD) && permissionCode.Equals("LicensePermission"))
                {
                    BasePermissionEntity permissionEntity = new BasePermissionEntity
                    {
                        ID = "LicensePermission",
                        Code = "LicensePermission",
                        FullName = "可授权的权限",
                        IsScope = true,
                        Enabled = true,
                        AllowDelete = false,
                        AllowEdit = false
                    };
                    dao.AddEntity(permissionEntity);
                    iD = permissionEntity.ID;
                }
                dTByUser = dao.GetDTByUser(userID, iD);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dTByUser;
        }

        public DataTable GetPermissionDTByUser(BaseUserInfo userInfo, string userID)
        {
            DataTable dT = new DataTable(BasePermissionTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                if (this.IsAdministratorByUser(dbHelper, userInfo, userID))
                {
                    dT = new BasePermissionAdminDao(dbHelper, userInfo).GetDT();
                }
                else
                {
                    dT = BaseResourcePermissionDao.Instance.GetPermissionByUser(dbHelper, userID);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dT;
        }

        public string[] GetResourcePermissionIDs(BaseUserInfo userInfo, string resourceCategory, string resourceID)
        {
            string[] strArray = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string[] names = new string[2];
                string[] values = new string[2];
                names[0] = BaseResourcePermissionTable.FieldResourceCategory;
                values[0] = resourceCategory;
                names[1] = BaseResourcePermissionTable.FieldResourceID;
                values[1] = resourceID;
                strArray = BaseBusinessLogic.FieldToArray(DbLogic.GetDT(dbHelper, BaseResourcePermissionTable.TableName, names, values), BaseResourcePermissionTable.FieldPermissionID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return strArray;
        }

        public string[] GetResourceScopeTargetIDs(BaseUserInfo userInfo, string resourceCategory, string resourceID, string targetCategory, string permissionCode)
        {
            string[] strArray = new string[0];
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string str = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, permissionCode);
                string[] names = new string[5];
                string[] values = new string[5];
                names[0] = BaseResourcePermissionScopeTable.FieldResourceCategory;
                values[0] = resourceCategory;
                names[1] = BaseResourcePermissionScopeTable.FieldResourceID;
                values[1] = resourceID;
                names[2] = BaseResourcePermissionScopeTable.FieldPermissionID;
                values[2] = str;
                names[3] = BaseResourcePermissionScopeTable.FieldTargetCategory;
                values[3] = targetCategory;
                strArray = BaseBusinessLogic.FieldToArray(DbLogic.GetDT(dbHelper, BaseResourcePermissionTable.TableName, names, values), BaseResourcePermissionScopeTable.FieldTargetID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return strArray;
        }

        public DataTable GetRoleDTByPermission(BaseUserInfo userInfo, string userID, string permissionScopeCode)
        {
            DataTable dT = new DataTable(BaseRoleTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                if (userInfo.IsAdministrator || string.IsNullOrEmpty(permissionScopeCode))
                {
                    dT = new BaseRoleDao(dbHelper, userInfo).GetDT();
                }
                else
                {
                    dT = new BaseResourcePermissionScopeDao(dbHelper, userInfo).GetRoleDT(userInfo.ID, permissionScopeCode);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return dT;
        }

        public string[] GetRoleIDsByPermission(BaseUserInfo userInfo, string userID, string permissionScopeCode)
        {
            string[] roleIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string.IsNullOrEmpty(permissionScopeCode);
                roleIDs = new BaseResourcePermissionScopeDao(dbHelper, userInfo).GetRoleIDs(userID, permissionScopeCode);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return roleIDs;
        }

        public string[] GetRoleLicensePermissionIDs(BaseUserInfo userInfo, string roleID)
        {
            string[] licensePermissionIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
                licensePermissionIDs = new BaseRolePermissionScopeDao(dbHelper, userInfo).GetLicensePermissionIDs(roleID);
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return licensePermissionIDs;
        }

        public string[] GetRolePermissionIDs(BaseUserInfo userInfo, string roleID)
        {
            string[] permissionIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
                permissionIDs = new BaseRolePermissionDao(dbHelper, userInfo).GetPermissionIDs(roleID);
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return permissionIDs;
        }

        public string[] GetRoleScopeModuleIDs(BaseUserInfo userInfo, string roleID, string permissionCode)
        {
            string[] moduleIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionScopeDao dao = new BaseRolePermissionScopeDao(dbHelper, userInfo);
                string permissionID = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, permissionCode);
                moduleIDs = dao.GetModuleIDs(roleID, permissionID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return moduleIDs;
        }

        public string[] GetRoleScopeOrganizeIDs(BaseUserInfo userInfo, string roleID, string permissionID)
        {
            string[] organizeIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                organizeIDs = new BaseRolePermissionScopeDao(dbHelper, userInfo).GetOrganizeIDs(roleID, permissionID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return organizeIDs;
        }

        public DataTable GetUserDTByPermission(BaseUserInfo userInfo, string userID, string permissionScopeCode)
        {
            DataTable userDT = new DataTable(BaseStaffTable.TableName);
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseResourcePermissionScopeDao dao = new BaseResourcePermissionScopeDao(dbHelper, userInfo);
                if (!string.IsNullOrEmpty(permissionScopeCode))
                {
                    userDT = dao.GetUserDT(userInfo.ID, permissionScopeCode);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return userDT;
        }

        public string[] GetUserIDsByPermission(BaseUserInfo userInfo, string userID, string permissionScopeCode)
        {
            string[] userIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string.IsNullOrEmpty(permissionScopeCode);
                userIDs = new BaseResourcePermissionScopeDao(dbHelper, userInfo).GetUserIDs(userID, permissionScopeCode);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return userIDs;
        }

        public string[] GetUserLicensePermissionIDs(BaseUserInfo userInfo, string userID)
        {
            string[] licensePermissionIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
                licensePermissionIDs = new BaseUserPermissionScopeDao(dbHelper, userInfo).GetLicensePermissionIDs(userID);
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return licensePermissionIDs;
        }

        public string[] GetUserPermissionIDs(BaseUserInfo userInfo, string userID)
        {
            string[] permissionIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
                permissionIDs = new BaseUserPermissionDao(dbHelper, userInfo).GetPermissionIDs(userID);
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return permissionIDs;
        }

        public PermissionScope GetUserPermissionScope(BaseUserInfo userInfo, string userID, string permissionScopeCode)
        {
            PermissionScope none = PermissionScope.None;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                none = new BaseResourcePermissionScopeDao(dbHelper, userInfo).GetUserPermissionScope(userID, permissionScopeCode);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return none;
        }

        public string[] GetUserScopeModuleIDs(BaseUserInfo userInfo, string userID, string permissionCode)
        {
            string[] moduleIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                string permissionID = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, permissionCode);
                moduleIDs = dao.GetModuleIDs(userID, permissionID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return moduleIDs;
        }

        public string[] GetUserScopeOrganizeIDs(BaseUserInfo userInfo, string userID, string permissionScopeID)
        {
            string[] organizeIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                organizeIDs = new BaseUserPermissionScopeDao(dbHelper, userInfo).GetOrganizeIDs(userID, permissionScopeID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return organizeIDs;
        }

        public string[] GetUserScopeRoleIDs(BaseUserInfo userInfo, string userID, string permissionScopeID)
        {
            string[] roleIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                roleIDs = new BaseUserPermissionScopeDao(dbHelper, userInfo).GetRoleIDs(userID, permissionScopeID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return roleIDs;
        }

        public string[] GetUserScopeUserIDs(BaseUserInfo userInfo, string userID, string permissionScopeID)
        {
            string[] userIDs = null;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                userIDs = new BaseUserPermissionScopeDao(dbHelper, userInfo).GetUserIDs(userID, permissionScopeID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return userIDs;
        }

        public int GrantResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceID, string[] grantPermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                new BaseRolePermissionScopeDao(dbHelper, userInfo);
                if (grantPermissionIDs != null)
                {
                    string[] strArray = BaseSequenceDao.Instance.GetBatchSequence(dbHelper, BaseResourcePermissionTable.TableName, grantPermissionIDs.Length);
                    BaseResourcePermissionDao dao = new BaseResourcePermissionDao(dbHelper, userInfo);
                    for (int i = 0; i < grantPermissionIDs.Length; i++)
                    {
                        BaseResourcePermissionEntity resourcePermissionEntity = new BaseResourcePermissionEntity
                        {
                            ID = strArray[i],
                            ResourceCategory = resourceCategory,
                            ResourceID = resourceID,
                            PermissionID = grantPermissionIDs[i]
                        };
                        dao.Add(resourcePermissionEntity);
                        num++;
                    }
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantResourceTargetScope(BaseUserInfo userInfo, string resourceCategory, string resourceID, string targetCategory, string[] grantTargetIDs, string permissionID)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseResourcePermissionScopeDao dao = new BaseResourcePermissionScopeDao(dbHelper, userInfo);
                BaseResourcePermissionScopeEntity resourcePermissionScope = new BaseResourcePermissionScopeEntity
                {
                    ResourceCategory = resourceCategory,
                    ResourceID = resourceID,
                    TargetCategory = targetCategory,
                    PermissionID = permissionID
                };
                for (int i = 0; i < grantTargetIDs.Length; i++)
                {
                    resourcePermissionScope.TargetID = grantTargetIDs[i];
                    dao.Add(resourcePermissionScope);
                    num++;
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantRoleLicensePermission(BaseUserInfo userInfo, string roleID, string[] grantPermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionScopeDao dao = new BaseRolePermissionScopeDao(dbHelper, userInfo);
                if (grantPermissionIDs != null)
                {
                    num += dao.GrantLicense(roleID, grantPermissionIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantRoleModuleScope(BaseUserInfo userInfo, string roleID, string[] grantModuleIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionScopeDao dao = new BaseRolePermissionScopeDao(dbHelper, userInfo);
                if (grantModuleIDs != null)
                {
                    string permissionID = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, "ModuleAccess");
                    num += dao.GrantModule(roleID, permissionID, grantModuleIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantRoleOrganizeScope(BaseUserInfo userInfo, string roleID, string permissionID, string[] grantOrganizeIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionScopeDao dao = new BaseRolePermissionScopeDao(dbHelper, userInfo);
                if (grantOrganizeIDs != null)
                {
                    num += dao.GrantOrganize(roleID, permissionID, grantOrganizeIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public string GrantRolePermission(BaseUserInfo userInfo, string roleName, string permissionCode)
        {
            string str = string.Empty;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string str2 = new BaseRoleDao(dbHelper, userInfo).FindID(BaseRoleTable.FieldRealname, roleName);
                string str3 = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, permissionCode);
                if (!string.IsNullOrEmpty(str2) && !string.IsNullOrEmpty(str3))
                {
                    str = new BaseRolePermissionDao(dbHelper, userInfo).Grant(str2, str3);
                }
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return str;
        }

        public int GrantRolePermission(BaseUserInfo userInfo, string roleID, string[] grantPermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionDao dao = new BaseRolePermissionDao(dbHelper, userInfo);
                if (grantPermissionIDs != null)
                {
                    num += dao.Grant(roleID, grantPermissionIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantUserLicensePermission(BaseUserInfo userInfo, string userID, string[] grantPermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (grantPermissionIDs != null)
                {
                    num += dao.GrantLicense(userID, grantPermissionIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantUserModuleScope(BaseUserInfo userInfo, string userID, string[] grantModuleIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (grantModuleIDs != null)
                {
                    string permissionID = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, "ModuleAccess");
                    num += dao.GrantModule(userID, permissionID, grantModuleIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantUserOrganizeScope(BaseUserInfo userInfo, string userID, string permissionScopeID, string[] grantOrganizeIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (grantOrganizeIDs != null)
                {
                    num += dao.GrantOrganize(userID, permissionScopeID, grantOrganizeIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public string GrantUserPermission(BaseUserInfo userInfo, string userName, string permissionCode)
        {
            string str = string.Empty;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string str2 = new BaseUserDao(dbHelper, userInfo).FindID(BaseUserTable.FieldUsername, userName);
                string str3 = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, permissionCode);
                if (!string.IsNullOrEmpty(str2) && !string.IsNullOrEmpty(str3))
                {
                    str = new BaseUserPermissionDao(dbHelper, userInfo).Grant(str2, str3);
                }
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return str;
        }

        public int GrantUserPermission(BaseUserInfo userInfo, string userID, string[] grantPermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionDao dao = new BaseUserPermissionDao(dbHelper, userInfo);
                if (grantPermissionIDs != null)
                {
                    num += dao.Grant(userID, grantPermissionIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantUserRoleScope(BaseUserInfo userInfo, string userID, string permissionScopeID, string[] grantRoleIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (grantRoleIDs != null)
                {
                    num += dao.GrantRole(userID, permissionScopeID, grantRoleIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int GrantUserUserScope(BaseUserInfo userInfo, string userID, string permissionScopeID, string[] grantUserIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (grantUserIDs != null)
                {
                    num += dao.GrantUser(userID, permissionScopeID, grantUserIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public bool IsAdministrator(BaseUserInfo userInfo)
        {
            return this.IsAdministratorByUser(userInfo, userInfo.ID);
        }

        public bool IsAdministratorByUser(BaseUserInfo userInfo, string userID)
        {
            bool flag = false;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                flag = this.IsAdministratorByUser(dbHelper, userInfo, userID);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return flag;
        }

        public bool IsAdministratorByUser(IDbHelper dbHelper, BaseUserInfo userInfo, string userID)
        {
            if (userID.Equals("Administrator"))
            {
                return true;
            }
            BaseUserEntity entity = new BaseUserDao(dbHelper, userInfo).GetEntity(userID);
            if (!string.IsNullOrEmpty(entity.Role) && entity.Role.Equals("Administrators"))
            {
                return true;
            }
            string[] roleIDs = new BaseUserRoleDao(dbHelper, userInfo).GetRoleIDs(userID);
            for (int i = 0; i < roleIDs.Length; i++)
            {
                if (roleIDs[i].Equals("Administrators"))
                {
                    return true;
                }
            }
            return false;
        }

        public bool IsAuthorized(BaseUserInfo userInfo, string permissionCode)
        {
            return this.IsAuthorizedByUser(userInfo, userInfo.ID, permissionCode);
        }

        public bool IsAuthorizedByUser(BaseUserInfo userInfo, string userID, string permissionCode)
        {
            bool flag = false;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                flag = this.IsAdministratorByUser(dbHelper, userInfo, userID);
                if (flag)
                {
                    return flag;
                }
                flag = BaseResourcePermissionDao.Instance.CheckPermissionByUser(dbHelper, userID, permissionCode);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return flag;
        }

        public bool IsInRole(BaseUserInfo userInfo, string userID, string roleName)
        {
            bool flag = false;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string str = new BaseRoleDao(dbHelper, userInfo).GetProperty(BaseRoleTable.FieldRealname, roleName, BaseRoleTable.FieldID);
                string str2 = new BaseUserDao(dbHelper, userInfo).GetProperty(BaseUserTable.FieldID, userID, BaseUserTable.FieldRole);
                if (!string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(str2))
                {
                    flag = str2.Equals(str);
                }
                else if (!string.IsNullOrEmpty(str))
                {
                    BaseUserRoleDao dao3 = new BaseUserRoleDao(dbHelper, userInfo);
                    string[] names = new string[] { BaseUserRoleTable.FieldUserID, BaseUserRoleTable.FieldRoleID, BaseUserRoleTable.FieldEnabled };
                    object[] values = new object[] { userID, str, "1" };
                    flag = dao3.Exists(names, values);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return flag;
        }

        public void Load()
        {
        }

        public bool ModuleIsAuthorized(BaseUserInfo userInfo, string moduleCode)
        {
            return this.ModuleIsAuthorizedByUser(userInfo, userInfo.ID, moduleCode);
        }

        public bool ModuleIsAuthorizedByUser(BaseUserInfo userInfo, string userID, string moduleCode)
        {
            bool flag = false;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                if (this.IsAdministratorByUser(dbHelper, userInfo, userID))
                {
                    return true;
                }
                BaseModuleDao dao = new BaseModuleDao(dbHelper, userInfo);
                foreach (DataRow row in dao.GetDTByUser(userID).Rows)
                {
                    if (row[BaseModuleTable.FieldCode].ToString().Equals(moduleCode))
                    {
                        flag = true;
                        break;
                    }
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return flag;
        }

        public bool ModuleIsAuthorizedByUser(BaseUserInfo userInfo, string userID, string moduleCode, string permissionCode)
        {
            bool flag = false;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                flag = this.IsAdministratorByUser(dbHelper, userInfo, userID);
                if (flag)
                {
                    return flag;
                }
                flag = BaseResourcePermissionScopeDao.Instance.ModuleIsAuthorized(dbHelper, userID, moduleCode, permissionCode);
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return flag;
        }

        public int RemoveUserFromRole(BaseUserInfo userInfo, string userName, string roleName)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string str = new BaseUserDao(dbHelper, userInfo).FindID(BaseUserTable.FieldUsername, userName);
                string str2 = new BaseRoleDao(dbHelper, userInfo).FindID(BaseRoleTable.FieldRealname, roleName);
                if (!string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(str2))
                {
                    num = new BaseUserRoleDao(dbHelper, userInfo).RemoveFormRole(str, str2);
                }
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceID, string[] revokePermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                new BaseRolePermissionScopeDao(dbHelper, userInfo);
                if (revokePermissionIDs != null)
                {
                    BaseResourcePermissionDao dao = new BaseResourcePermissionDao(dbHelper, userInfo);
                    string[] names = new string[3];
                    string[] strArray2 = new string[3];
                    names[0] = BaseResourcePermissionTable.FieldResourceCategory;
                    strArray2[0] = resourceCategory;
                    names[1] = BaseResourcePermissionTable.FieldResourceID;
                    strArray2[1] = resourceID;
                    names[2] = BaseResourcePermissionTable.FieldPermissionID;
                    for (int i = 0; i < revokePermissionIDs.Length; i++)
                    {
                        strArray2[2] = revokePermissionIDs[i];
                        num += dao.BatchDelete(names, (object[])strArray2);
                    }
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeResourceTargetScope(BaseUserInfo userInfo, string resourceCategory, string resourceID, string targetCategory, string[] revokeTargetIDs, string permissionID)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseResourcePermissionScopeDao dao = new BaseResourcePermissionScopeDao(dbHelper, userInfo);
                string[] names = new string[5];
                string[] strArray2 = new string[5];
                names[0] = BaseResourcePermissionScopeTable.FieldResourceCategory;
                strArray2[0] = resourceCategory;
                names[1] = BaseResourcePermissionScopeTable.FieldResourceID;
                strArray2[1] = resourceID;
                names[2] = BaseResourcePermissionScopeTable.FieldTargetCategory;
                strArray2[2] = targetCategory;
                names[3] = BaseResourcePermissionScopeTable.FieldPermissionID;
                strArray2[3] = permissionID;
                names[4] = BaseResourcePermissionScopeTable.FieldTargetID;
                for (int i = 0; i < revokeTargetIDs.Length; i++)
                {
                    strArray2[4] = revokeTargetIDs[i];
                    num += dao.BatchDelete(names, (object[])strArray2);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeRoleLicensePermission(BaseUserInfo userInfo, string roleID, string[] revokePermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionScopeDao dao = new BaseRolePermissionScopeDao(dbHelper, userInfo);
                if (revokePermissionIDs != null)
                {
                    num += dao.RevokeLicense(roleID, revokePermissionIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeRoleModuleScope(BaseUserInfo userInfo, string roleID, string[] revokeModuleIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionScopeDao dao = new BaseRolePermissionScopeDao(dbHelper, userInfo);
                if (revokeModuleIDs != null)
                {
                    string permissionID = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, "ModuleAccess");
                    num += dao.RevokeModule(roleID, permissionID, revokeModuleIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeRoleOrganizeScope(BaseUserInfo userInfo, string roleID, string permissionID, string[] revokeOrganizeIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionScopeDao dao = new BaseRolePermissionScopeDao(dbHelper, userInfo);
                if (revokeOrganizeIDs != null)
                {
                    num += dao.RevokeOrganize(roleID, permissionID, revokeOrganizeIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeRolePermission(BaseUserInfo userInfo, string roleName, string permissionCode)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string str = new BaseRoleDao(dbHelper, userInfo).FindID(BaseRoleTable.FieldRealname, roleName);
                string str2 = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, permissionCode);
                if (!string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(str2))
                {
                    num = new BaseRolePermissionDao(dbHelper, userInfo).Revoke(str, str2);
                }
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeRolePermission(BaseUserInfo userInfo, string roleID, string[] revokePermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseRolePermissionDao dao = new BaseRolePermissionDao(dbHelper, userInfo);
                if (revokePermissionIDs != null)
                {
                    num += dao.Revoke(roleID, revokePermissionIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeUserLicensePermission(BaseUserInfo userInfo, string userID, string[] revokePermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (revokePermissionIDs != null)
                {
                    num += dao.RevokeLicense(userID, revokePermissionIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeUserModuleScope(BaseUserInfo userInfo, string userID, string[] revokeModuleIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (revokeModuleIDs != null)
                {
                    string permissionID = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, "ModuleAccess");
                    num += dao.RevokeModule(userID, permissionID, revokeModuleIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeUserOrganizeScope(BaseUserInfo userInfo, string userID, string permissionScopeID, string[] revokeOrganizeIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (revokeOrganizeIDs != null)
                {
                    num += dao.RevokeOrganize(userID, permissionScopeID, revokeOrganizeIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeUserPermission(BaseUserInfo userInfo, string userName, string permissionCode)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                string str = new BaseUserDao(dbHelper, userInfo).FindID(BaseUserTable.FieldUsername, userName);
                string str2 = new BasePermissionAdminDao(dbHelper, userInfo).FindID(BasePermissionTable.FieldCode, permissionCode);
                if (!string.IsNullOrEmpty(str) && !string.IsNullOrEmpty(str2))
                {
                    num = new BaseUserPermissionDao(dbHelper, userInfo).Revoke(str, str2);
                }
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeUserPermission(BaseUserInfo userInfo, string userID, string[] revokePermissionIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionDao dao = new BaseUserPermissionDao(dbHelper, userInfo);
                if (revokePermissionIDs != null)
                {
                    num += dao.Revoke(userID, revokePermissionIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeUserRoleScope(BaseUserInfo userInfo, string userID, string permissionScopeID, string[] revokeRoleIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (revokeRoleIDs != null)
                {
                    num += dao.RevokeRole(userID, permissionScopeID, revokeRoleIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public int RevokeUserUserScope(BaseUserInfo userInfo, string userID, string permissionScopeID, string[] revokeUserIDs)
        {
            int num = 0;
            IDbHelper dbHelper = DbHelperFactory.GetHelper();
            try
            {
                dbHelper.Open();
                BaseUserPermissionScopeDao dao = new BaseUserPermissionScopeDao(dbHelper, userInfo);
                if (revokeUserIDs != null)
                {
                    num += dao.RevokeUser(userID, permissionScopeID, revokeUserIDs);
                }
                BaseLogDao.Instance.Add(dbHelper, userInfo, MethodBase.GetCurrentMethod());
            }
            catch (Exception exception)
            {
                BaseExceptionDao.LogException(dbHelper, userInfo, exception);
                throw exception;
            }
            finally
            {
                dbHelper.Close();
            }
            return num;
        }

        public static PermissionService Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (locker)
                    {
                        if (instance == null)
                        {
                            instance = new PermissionService();
                        }
                    }
                }
                return instance;
            }
        }
    }
}